package com.gitee.chenyaohua.oa.service.impl;

import com.gitee.chenyaohua.oa.service.VerificationCodeService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.concurrent.ThreadLocalRandom;

@Service
@CacheConfig(cacheNames = "verificationCode")
public class VerificationCodeServiceImp implements VerificationCodeService {
    /**
     * 获取验证码
     * @param email
     * @return
     */
    @Cacheable(key = "#email")
    @Override
    public String getVerificationCode(String email) {
        return "";
    }

    /**
     * 重置验证码
     * @param email
     * @return
     */
    @CachePut(key = "#email")
    @Override
    public String resetVerificationCode(String email) {
        int asInt = ThreadLocalRandom.current().nextInt(0, 999999);
        return String.format("%1$06d",asInt);
    }

    /**
     * 删除验证码
     * @param email
     */
    @CacheEvict(key = "#email")
    @Override
    public void cleanVerificationCode(String email) {}

}
